<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        img {
            position: absolute;
            top: 2px;
        }
    </style>
</head>

<body>
    <img src="images/angel.gif" alt="" id="pic">
    <script>
        var pic = document.querySelector('#pic')
        document.addEventListener('mousemove', function(a) {
            var x = a.clientX;
            var y = a.clientY;
            pic.style.left = x - 50 + 'px';
            pic.style.top = y - 40 + 'px';
        })

        document.addEventListener('click', function(e) {
            var e = e || window.event
            var x = e.clientX
            var y = e.clientY
            var imgNode = document.createElement('img')
            imgNode.src = 'images/爱心.png'
            var width = getRandom(100, 20)
            imgNode.width = width
            imgNode.style.left = (x - width / 2) + 'px'
            imgNode.style.top = (y - width / 2) + 'px'
            document.body.appendChild(imgNode)
        })

        function getRandom(min, max) {
            min = Math.ceil(min);
            max = Math.floor(max);
            return Math.floor(Math.random() * (max - min + 1)) + min; //含最大值，含最小值 
        }
    </script>
</body>

</html>